package com.atguigu.tingshu.account.api;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.tingshu.account.service.RechargeInfoService;
import com.atguigu.tingshu.common.login.GuiguLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.account.RechargeInfo;
import com.atguigu.tingshu.vo.account.RechargeInfoVo;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "充值管理")
@RestController
@RequestMapping("api/account/rechargeInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class RechargeInfoApiController {

	@Autowired
	private RechargeInfoService rechargeInfoService;

	@GuiguLogin
	@Operation(summary = "充值接口")
	@PostMapping("submitRecharge")
	public Result submitRecharge(@RequestBody RechargeInfoVo rechargeInfoVo){
		//orderNo
		JSONObject jsonObject = rechargeInfoService.submitRecharge(rechargeInfoVo);
		return Result.ok(jsonObject);
	}

	@Operation(summary = "内部接口： 根据订单号查询充值记录")
	@GetMapping("getRechargeByOrderNo/{orderNo}")
	public Result<RechargeInfo> getRechargeByOrderNo(@PathVariable("orderNo")String orderNo){
		RechargeInfo rechargeInfo = rechargeInfoService.getOne(Wrappers.lambdaQuery(RechargeInfo.class)
				.eq(RechargeInfo::getOrderNo, orderNo));
		return  Result.ok(rechargeInfo);
	}

	@Operation(summary = "内部接口： 根据订单号更新充值记录的状态")
	@GetMapping("updateRechargeByOrderNo/{orderNo}/{orderStatus}")
	public Result<Boolean> updateRechargeByOrderNo(@PathVariable("orderNo")String orderNo,
												   @PathVariable("orderStatus")String orderStatus ){
		return  Result.ok(rechargeInfoService.updateRechargeByOrderNo(orderNo,orderStatus));
	}


}

